/*
 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdio.h>
#include "unity.h"
#include "driver/i2c.h"
#include "mpu6050/mpu6050.h"
#include "esp_system.h"
#include "esp_log.h"
#include "aht10/aht10.h"
#include "uart_wave/uart_wave.h"
#include "cJSON.h"
#include "analyse/analyse_cjson.h"

static const char *MPU_TAG = "mpu6050 test";
static const char *AHT_TAG = "AHT10 test";
static const char *UART_TAG = "ultrasonic test";

void app_main(void) {

    // mpu6050部分
    mpu6050_acce_value_t acce;      // 加速度
    mpu6050_gyro_value_t gyro;      // 陀螺仪
    mpu6050_init();

    // AHT10部分
    float temperature;          // 温度
    uint32_t humidity;          // 湿度
    aht10_init();

    // 超声波部分
    uart_config_init();
    int distance = 0;               // 距离

//    cJSON *json = NULL;
//    i2c_scan_config config;
//    recive_i2c_device_config(json, &config);

    while (1) {
        // mpu6050部分
        mpu6050_get(&acce, &gyro);
        ESP_LOGI(MPU_TAG, "acce_x:%.2f, acce_y:%.2f, acce_z:%.2f\n", acce.acce_x, acce.acce_y, acce.acce_z);
        ESP_LOGI(MPU_TAG, "gyro_x:%.2f, gyro_y:%.2f, gyro_z:%.2f\n", gyro.gyro_x, gyro.gyro_y, gyro.gyro_z);
        vTaskDelay(pdMS_TO_TICKS(500));

//        // AHT10部分
        ReadData(&temperature, &humidity);
        ESP_LOGI(AHT_TAG, "temperature:%.2f, humidity: %lu\n", temperature / 10, humidity / 10);
        vTaskDelay(pdMS_TO_TICKS(500));

        // 超声波部分
        read_distance(&distance);
        printf("distance:%d mm\r\n",distance);
//        uart_send_int(distance);

    }

}
